home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload Trio 2 / Shareware Overload Trio Volume 2 (Chestnut CD-ROM).ISO / dir24 / jnos110g.zip / IP.H < prev    next >
C/C++ Source or Header  |  1994-04-17  |  9KB  |  252 lines

  1. /* Mods by PA0GRI (WFM IP access code ) */
  2. #ifndef _IP_H
  3. #define _IP_H
  4.   
  5. #ifndef _GLOBAL_H
  6. #include "global.h"
  7. #endif
  8.   
  9. #ifndef _MBUF_H
  10. #include "mbuf.h"
  11. #endif
  12.   
  13. #ifndef _IFACE_H
  14. #include "iface.h"
  15. #endif
  16.   
  17. #ifndef _INTERNET_H
  18. #include "internet.h"
  19. #endif
  20.   
  21. #ifndef _TIMER_H
  22. #include "timer.h"
  23. #endif
  24.   
  25. #define TLB     30  /* Default reassembly timeout, sec */
  26. #define IPVERSION   4
  27. #define IP_CS_OLD   1   /* use saved checksum */
  28. #define IP_CS_NEW   0   /* calculate checksum */
  29.   
  30. extern char Hashtab[];  /* Modulus lookup table */
  31.   
  32. /* SNMP MIB variables, used for statistics and control. See RFC 1066 */
  33. extern struct mib_entry Ip_mib[];
  34. #define ipForwarding        Ip_mib[1].value.integer
  35. #define ipDefaultTTL        Ip_mib[2].value.integer
  36. #define ipInReceives        Ip_mib[3].value.integer
  37. #define ipInHdrErrors       Ip_mib[4].value.integer
  38. #define ipInAddrErrors      Ip_mib[5].value.integer
  39. #define ipForwDatagrams     Ip_mib[6].value.integer
  40. #define ipInUnknownProtos   Ip_mib[7].value.integer
  41. #define ipInDiscards        Ip_mib[8].value.integer
  42. #define ipInDelivers        Ip_mib[9].value.integer
  43. #define ipOutRequests       Ip_mib[10].value.integer
  44. #define ipOutDiscards       Ip_mib[11].value.integer
  45. #define ipOutNoRoutes       Ip_mib[12].value.integer
  46. #define ipReasmTimeout      Ip_mib[13].value.integer
  47. #define ipReasmReqds        Ip_mib[14].value.integer
  48. #define ipReasmOKs      Ip_mib[15].value.integer
  49. #define ipReasmFails        Ip_mib[16].value.integer
  50. #define ipFragOKs       Ip_mib[17].value.integer
  51. #define ipFragFails     Ip_mib[18].value.integer
  52. #define ipFragCreates       Ip_mib[19].value.integer
  53.   
  54. #define NUMIPMIB    19
  55.   
  56. /* IP header, INTERNAL representation */
  57. #define IPLEN       20  /* Length of standard IP header */
  58. #define IP_MAXOPT   40  /* Largest option field, bytes */
  59. struct ip {
  60.     int32 source;       /* Source address */
  61.     int32 dest;     /* Destination address */
  62.     int16 length;       /* Total length */
  63.     int16 id;       /* Identification */
  64.     int16 offset;       /* Fragment offset in bytes */
  65.     int16 checksum;     /* Header checksum */
  66.   
  67.     struct {
  68.         char congest;   /* Congestion experienced bit (exp) */
  69.         char df;    /* Don't fragment flag */
  70.         char mf;    /* More Fragments flag */
  71.     } flags;
  72.   
  73.     char version;       /* IP version number */
  74.     char tos;       /* Type of service */
  75.     char ttl;       /* Time to live */
  76.     char protocol;      /* Protocol */
  77.     char optlen;        /* Length of options field, bytes */
  78.     char options[IP_MAXOPT];/* Options field */
  79. };
  80. #define NULLIP  (struct ip *)0
  81.   
  82. /* Fields in option type byte */
  83. #define OPT_COPIED  0x80    /* Copied-on-fragmentation flag */
  84. #define OPT_CLASS   0x60    /* Option class */
  85. #define OPT_NUMBER  0x1f    /* Option number */
  86.   
  87. /* IP option numbers */
  88. #define IP_EOL      0   /* End of options list */
  89. #define IP_NOOP     1   /* No Operation */
  90. #define IP_SECURITY 2   /* Security parameters */
  91. #define IP_LSROUTE  3   /* Loose Source Routing */
  92. #define IP_TIMESTAMP    4   /* Internet Timestamp */
  93. #define IP_RROUTE   7   /* Record Route */
  94. #define IP_STREAMID 8   /* Stream ID */
  95. #define IP_SSROUTE  9   /* Strict Source Routing */
  96.   
  97. /* Timestamp option flags */
  98. #define TS_ONLY     0   /* Time stamps only */
  99. #define TS_ADDRESS  1   /* Addresses + Time stamps */
  100. #define TS_PRESPEC  3   /* Prespecified addresses only */
  101.   
  102. /* IP routing table entry */
  103. struct route {
  104.     struct route *prev; /* Linked list pointers */
  105.     struct route *next;
  106.     int32 target;       /* Target IP address */
  107.     unsigned int bits;  /* Number of significant bits in target */
  108.     int32 gateway;      /* IP address of local gateway for this target */
  109.     int32 metric;       /* Hop count or whatever */
  110.     struct iface *iface;    /* Device interface structure */
  111.     int flags;
  112. #define RTPRIVATE   0x1 /* Should the world be told of this route ? */
  113. #define RTTRIG  0x2     /* Trigger is pending for this route */
  114.     struct timer timer; /* Time until aging of this entry */
  115.     int32 uses;     /* Usage count */
  116. #ifdef RIP
  117.     int16 route_tag;    /* Tag used by RIP-2, N0POY 4/93 */
  118. #endif
  119. };
  120. #define NULLROUTE   (struct route *)0
  121. extern struct route *Routes[32][HASHMOD];   /* Routing table */
  122. extern struct route R_default;          /* Default route entry */
  123.   
  124. /* IP access header entry  (WFM) */
  125. struct rtaccess{
  126.     struct rtaccess *nxtiface;  /* Linked list pointer */
  127.     struct rtaccess *nxtbits;
  128.     int16 status;       /* 0=permit, 1=deny */
  129.     int16 protocol;     /* 0=any, otherwise IP protocol # */
  130.     int32 source;       /* Source IP address */
  131.     unsigned int sbits; /* Number of significant bits in source */
  132.     int32 target;       /* Target IP address */
  133.     unsigned int bits;  /* Number of significant bits in target */
  134.     struct iface *iface;    /* Device interface structure */
  135.     int16 lowport;      /* tcp & udp port range. low=0 implies all */
  136.     int16 highport;
  137. };
  138. #define NULLACCESS  (struct rtaccess *)0
  139. extern struct rtaccess *IPaccess;
  140. /* end WFM access control */
  141.   
  142. /* Cache for the last-used routing entry, speeds up the common case where
  143.  * we handle a burst of packets to the same destination
  144.  */
  145. struct rt_cache {
  146.     int32 target;
  147.     struct route *route;
  148. };
  149. extern struct rt_cache Rt_cache;
  150.   
  151. /* Reassembly descriptor */
  152. struct reasm {
  153.     struct reasm *next; /* Linked list pointer */
  154.     struct timer timer; /* Reassembly timeout timer */
  155.     struct frag *fraglist;  /* Head of data fragment chain */
  156.     int16 length;       /* Entire datagram length, if known */
  157.     int32 source;       /* src/dest/id/protocol uniquely describe a datagram */
  158.     int32 dest;
  159.     int16 id;
  160.     char protocol;
  161. };
  162. #define NULLREASM   (struct reasm *)0
  163.   
  164. /* Fragment descriptor in a reassembly list */
  165. struct frag {
  166.     struct frag *prev;  /* Previous fragment on list */
  167.     struct frag *next;  /* Next fragment */
  168.     struct mbuf *buf;   /* Actual fragment data */
  169.     int16 offset;       /* Starting offset of fragment */
  170.     int16 last;     /* Ending offset of fragment */
  171. };
  172. #define NULLFRAG    (struct frag *)0
  173.   
  174. extern struct reasm *Reasmq;    /* The list of reassembly descriptors */
  175.   
  176. /* Structure for handling raw IP user sockets */
  177. struct raw_ip {
  178.     struct raw_ip *next;    /* Linked list pointer */
  179.   
  180.     struct mbuf *rcvq;  /* receive queue */
  181.     void (*r_upcall) __ARGS((struct raw_ip *));
  182.     int protocol;       /* Protocol */
  183.     int user;       /* User linkage */
  184. };
  185. #define NULLRIP ((struct raw_ip *)0)
  186. extern struct raw_ip *Raw_ip;
  187.   
  188. /* Transport protocol link table */
  189. struct iplink {
  190.     char proto;
  191.     void (*funct) __ARGS((struct iface *,struct ip *,struct mbuf *,int));
  192. };
  193. extern struct iplink Iplink[];
  194. extern int Tcp_interact[];
  195.   
  196. /* IP heard structure */
  197. struct iph {
  198.     struct iph *next;
  199.     int32 addr;
  200.     struct iface *iface;
  201.     long count;
  202.     long time;
  203. };
  204. #define NULLIPH (struct iph *)0
  205. extern struct iph *Iph;
  206. #define MAXIPHEARD 16
  207.   
  208. /* In ip.c: */
  209. void ip_garbage __ARGS((int drastic));
  210. void ip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  211. int rxbroadcast));
  212. void ipip_recv __ARGS((struct iface *iface,struct ip *ip,struct mbuf *bp,
  213. int rxbroadcast));
  214. int ip_send __ARGS((int32 source,int32 dest,char protocol,char tos,char ttl,
  215. struct mbuf *bp,int16 length,int16 id,char df));
  216. struct raw_ip *raw_ip __ARGS((int protocol,void (*r_upcall) __ARGS((struct raw_ip *)) ));
  217. void del_ip __ARGS((struct raw_ip *rrp));
  218.   
  219. /* In iproute.c: */
  220. void ipinit __ARGS((void));
  221. int16 ip_mtu __ARGS((int32 addr));
  222. int ip_encap __ARGS((struct mbuf *bp,struct iface *iface,int32 gateway,
  223. int prec,int del,int tput,int rel));
  224. void ip_proc __ARGS((struct iface *ifp,struct mbuf *bp));
  225. int ip_route __ARGS((struct iface *i_iface,struct mbuf *bp,int rxbroadcast));
  226. int32 locaddr __ARGS((int32 addr));
  227. void rt_merge __ARGS((int trace));
  228. struct route *rt_add __ARGS((int32 target,unsigned int bits,int32 gateway,
  229. struct iface *iface,int32 metric,int32 ttl,char private));
  230. int rt_drop __ARGS((int32 target,unsigned int bits));
  231. struct route *rt_lookup __ARGS((int32 target));
  232. struct route *rt_blookup __ARGS((int32 target,unsigned int bits));
  233. int ip_check __ARGS((struct rtaccess *accptr,int16 protocol,
  234. int32 src,int32 dest,int16 port));
  235. void addaccess __ARGS((int16 protocol,int32 source,unsigned int sbits,
  236. int32 target,unsigned int tbits,struct iface *ifp,
  237. int16 low,int16 high,int16 permit));
  238.   
  239. /* In iphdr.c: */
  240. int16 cksum __ARGS((struct pseudo_header *ph,struct mbuf *m,int16 len));
  241. int16 eac __ARGS((int32 sum));
  242. struct mbuf *htonip __ARGS((struct ip *ip,struct mbuf *data,int cflag));
  243. int ntohip __ARGS((struct ip *ip,struct mbuf **bpp));
  244.   
  245. /* In either lcsum.c or pcgen.asm: */
  246. int16 lcsum __ARGS((int16 *wp,int16 len));
  247.   
  248. /* In ipcmd.c */
  249. void log_ipheard __ARGS((int32 addr, struct iface *iface));
  250.   
  251. #endif /* _IP_H */
  252.